package main

import "math"

func distanceBetweenBusStops(distance []int, start int, destination int) int {
	N := len(distance)
	res1, res2 := 0, 0
	for i := start; i != destination; i = next(i, N) {
		res1 += distance[i]
	}
	for i := start; i != destination; i = prev(i, N) {
		res2 += distance[prev(i, N)]
	}
	return int(math.Min(float64(res1), float64(res2)))
}

func next(index, N int) int {
	return (index + 1) % N
}

func prev(index, N int) int {
	if index > 0 {
		return index - 1
	}
	return N - 1
}
